<template>
  <div class="container-y">
    <searchWrap @inputValue="inputValue"></searchWrap>
    <ul class="contacts-ul">
      <li class="contacts-li"
          v-for="item in searchList">
        <input class="checkInput"
               :value="item"
               type="checkbox"
               v-model="checked">
        <div class="txtWrap">
          <div class="name nameOnly">
            {{item.label}}
          </div>
          <div class="checkIcon"></div>
        </div>
      </li>
    </ul>
    <!--<noMoreData v-if="!searchList.length"></noMoreData>-->
    <div class="pdb"></div>
  </div>
</template>

<script>
  import searchWrap from "../commonComponents/search.vue"
  import noMoreData from "../commonComponents/noMoreData.vue"

  export default {
    data() {
      return {
        checked: [],
        searchList: [],
        headerRightType: {},
        headerFlag: "",
        id: "",
      }
    },
    methods: {
      init() {
        // type 1 事件
        this.headerRightType = this.$store.state.headerRightType;
        this.headerFlag = this.$store.state.showFlag;
        this.isFeedback = _methods.getUrlParam("isFeedback");
        this.id = _methods.getUrlParam("id");
        this.flag = _methods.getUrlParam("flag") - 0;
        _methods.headerTitleChange(112);
        _methods.headerRightShow({
          val: 112,
          txt: "确定"
        });
        let data = {
          isFeedback: this.isFeedback,
        };
        this.key = {
          1: "feedBackItemCheck",
          2: "feedBackItemCheckSafe",
        }[this.flag];
          console.log(this.key);
        _ajax.withLoading(_ajaxUrls.addTemList.url + "/" + this.id,
          data,
          (ajd) => {
            let aj = ajd.result;
            this.searchList = aj;
            _data[this.key] = aj;
            this.checked = this.$store.state[this.key];
            console.log(this.checked);
          },
          "get");
      },
      inputValue(v) {
        let k = v.toString().trim();
        if (k != "") {
          this.searchList = _data[this.key].filter((v) => {
            return v.label.indexOf(k) != -1;
          });
        } else {
          this.searchList = _data[this.key];
        }
      },
    },
    components: {
      searchWrap,
      noMoreData
    },
    created() {
      this.init();
    },
    mounted() {
      let self = this;
      _data.busInit.on_(() => {
        let c = self.checked;
        self.$store.commit("_" + this.key, c);
        _methods.goBack();
      });
    },
    beforeDestroy() {
      _data.busInit.off_();
      _methods.headerTitleChange(this.headerFlag, true);
      _methods.headerRightShow(this.headerRightType);
    }
  }

</script>
